<?php
class User extends CActiveRecord{
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }
    public function tableName() {
        parent::tableName();
        return 'users';
    }
    public function relations(){
        return array(
            'profile'=>array(self::HAS_ONE,'Profile','id'),
        );
    }
    public function rules() {
        parent::rules();
        return array(
            array('username,password,email','required'),
            array('username','isIssert'),
        );
    }
    public function isIssert($attribute,$params){
        $user = User::model()->findByAttributes(array('username'=>$this->username));
        if($user!==null){
            $this->addError('username','入力したユーザIDが既に存在しています、ご確認ください');
        }
    }
    public function attributeLabels() {
        parent::attributeLabels();
        return array(
            'id'=>'Id',
            'username'=>'ユーザID:',
            'password'=>'パスワード:',
            'email'=>'Eメール:',
        );
    }
    
}